home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 33.2 KB | 1,198 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawPart.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef TOOLFRM_H
- #include "ToolFrm.h"
- #endif
-
- #ifndef PALFRAME_H
- #include "PalFrame.h"
- #endif
-
- #ifndef PATFRAME_H
- #include "PatFrame.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef PRINTHDL_H
- #include "PrintHdl.h"
- #endif
-
- #ifndef GROUPCMD_H
- #include "GroupCmd.h"
- #endif
-
- #ifndef RULER_H
- #include "Ruler.h"
- #endif
-
- #ifndef SOM_ODFExamples_ODFDrawEmbeddedFramesIterator_xh
- #include "SOMIter.xh"
- #endif
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWSUUTIL_H
- #include "FWSUUtil.h"
- #endif
-
- #ifndef FWPXYITE_H
- #include "FWPxyIte.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWAPLEVT_H
- #include "FWAplEvt.h"
- #endif
-
- #ifndef FWCOLORP_H
- #include "FWColorP.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWFLOWIN_H
- #include "FWFloWin.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef FWARCSHP_H
- #include "FWArcShp.h"
- #endif
-
- #ifndef FWPRINFO_H
- #include "FWPrInfo.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- FW_DEFINE_CLASS_M2(CDrawPart, FW_CEmbeddingPart, FW_MEmbeddingPartScriptable)
- FW_DEFINE_AUTO(CDrawPart)
-
- //========================================================================================
- // class CDrawPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::CDrawPart(ODPart* odPart) :
- FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
- FW_MEmbeddingPartScriptable(),
- FW_MReceiver(),
- fNbEmbedded(0),
- fPartContent(NULL),
- fCurrentPenSize(FW_kFixedPos1),
- fRenderVerb(kFillFrame),
- fPaletteWindow(NULL),
- fPatternWindow(NULL),
- fToolsWindow(NULL),
- fToolFrame(NULL),
- fPaletteFrame(NULL),
- fPatternFrame(NULL),
- fPalettePresentation(NULL),
- fPatternPresentation(NULL),
- fToolPresentation(NULL),
- fMainPresentation(NULL),
- fAlignObjectsPresentation(NULL),
- fTool(kSelectTool),
- fFillColor(FW_kRGBWhite),
- fFrameColor(FW_kRGBBlack),
- fAutoGrid(TRUE),
- fUnit(cInchUnit),
- fArcUnit(cDegreesUnit),
- fPostCreated(FALSE)
- {
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::~CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::~CDrawPart()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ReleaseAll
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::ReleaseAll(Environment *ev)
- {
- FW_CEmbeddingPart::ReleaseAll(ev);
-
- delete fPaletteWindow;
- delete fPatternWindow;
- delete fToolsWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::Initialize(Environment *ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
- {
- // ----- Call Inherited Initialize -----
- FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
-
- fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
-
- #ifdef FW_BUILD_WIN
- // [HLX] Temporary embed menu for windows
- WinAddEmbedMenu(ev, GetMenuBar(ev));
- #endif
-
- // ----- We are using FW_CToggleItem and FW_CSubMenuItem so avoid dead stripping -----
- FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
- FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
-
- // ----- Tokenize -----
- fDrawSelection = FW_NEW(CDrawSelection, (ev, this)); // Attention I don't own the selection the presentation will
-
- fToolPresentation = RegisterPresentation(ev, kToolPresentation, FALSE);
- fPalettePresentation = RegisterPresentation(ev, kPalettePresentation, FALSE);
- fPatternPresentation = RegisterPresentation(ev, kPatternPresentation, FALSE);
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, kDrawViewNotRoot, kDrawView, fDrawSelection);
- fAlignObjectsPresentation = RegisterPresentation(ev, kAlignObjectsPresentation, FALSE);
-
- InitializePalettes(ev);
-
- // ----- Pattern Table -----
- fPatternTable[0] = FW_kBlackPat;
- fPatternTable[1] = FW_kWhitePat;
- fPatternTable[2] = FW_kGrayPat;
- fPatternTable[3] = FW_kLightGrayPat;
- fPatternTable[4] = FW_kDarkGrayPat;
- fPatternTable[5] = FW_kHorizontalPat;
- fPatternTable[6] = FW_kVerticalPat;
- fPatternTable[7] = FW_kFDiagonalPat;
- fPatternTable[8] = FW_kBDiagonalPat;
- fPatternTable[9] = FW_kCrossPat;
- fPatternTable[10] = FW_kDiagCrossPat;
- fPatternTable[11] = FW_kAntPat;
-
- fFillPatIndex = 0;
- fFramePatIndex = 0;
-
- // ----- Register PICT type -----
- RegisterKind(ev, 'PICT', kODPlatformDataType, FW_kDataInterchangeStorage, FW_kExportEnabled);
- }
-
- //------------------------------------------------------------------------------
- // CDrawPart::SetDrawingSize
- //------------------------------------------------------------------------------
-
- void CDrawPart::SetDrawingSize(Environment* ev, const FW_CPoint& newSize)
- {
- if(fDrawingSize != newSize)
- {
- fDrawingSize = newSize;
-
- FW_CPresentationFrameIterator ite(ev, fMainPresentation);
- for (CDrawFrame* theFrame = (CDrawFrame*) ite.First(ev); ite.IsNotComplete(ev); theFrame = (CDrawFrame*) ite.Next(ev))
- {
- theFrame->AdjustContentViewSize(ev, FW_kInvalidate);
-
- CRuler* horzRuler = (CRuler*) theFrame->FindViewByID(ev, kHorzRulerID);
- CRuler* vertRuler = (CRuler*) theFrame->FindViewByID(ev, kVertRulerID);
-
- FW_CPoint extent;
-
- extent = horzRuler->GetExtent(ev);
- extent.x = newSize.x;
- horzRuler->SetExtent(ev, extent);
-
- extent = vertRuler->GetExtent(ev);
- extent.y = newSize.y;
- vertRuler->SetExtent(ev, extent);
-
- theFrame->GetContentView(ev)->SetExtent(ev, fDrawingSize);
-
- theFrame->Invalidate(ev);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // CDrawPart::InitializePalettes
- //------------------------------------------------------------------------------
-
- void CDrawPart::InitializePalettes(Environment *ev)
- {
- FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
- fPatternWindow = new FW_CFloatingWindow(ev,
- this,
- fPatternPresentation,
- FW_CString32(""),
- FW_kZeroPoint,
- position,
- TRUE);
-
- fPaletteWindow = new FW_CFloatingWindow(ev,
- this,
- fPalettePresentation,
- FW_CString32(""),
- FW_kZeroPoint,
- position,
- TRUE);
-
- FW_CRect screenBounds;
- ::FW_GetMainScreenBounds(screenBounds);
- screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
-
- FW_CPoint windowSize(FW_IntToFixed(kToolsWindowWidth), FW_IntToFixed(kToolsWindowHeight));
- fToolsWindow = new FW_CFloatingWindow(ev,
- this,
- fToolPresentation,
- FW_CString32(""),
- windowSize,
- screenBounds.TopLeft(),
- TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::OnAcquireSelectionFocus
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::OnAcquireSelectionFocus(Environment* ev, CDrawFrame* frame)
- {
- static short done = false;
-
- if (!done && frame->IsRoot(ev) && !fToolsWindow->IsShown(ev))
- {
- done = TRUE;
- fToolsWindow->ShowHide(ev, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewDocumentWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* CDrawPart::NewDocumentWindow(Environment* ev)
- {
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- // ----- Add the rulers -----
- sbSize.x += kRulerWidth;
- sbSize.y += kRulerWidth;
-
- FW_CPoint drawingSize(fDrawingSize.x + sbSize.x, fDrawingSize.y + sbSize.y);
-
- FW_CRect screenBounds;
- ::FW_GetMainScreenBounds(screenBounds);
- screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
-
- // Make room for the tool palettes
- screenBounds.left += FW_IntToFixed(3 + kToolsWindowWidth + 3);
-
- return new FW_CWindow(ev,
- this,
- FW_CPart::fgViewAsFrameToken,
- fMainPresentation,
- drawingSize,
- screenBounds.TopLeft(),
- FW_kDocumentWindow);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InternalizeContent
- //---------------------------------------------------------------------------------------
- // I override FW_CPart::InternalizeContent because I want to read my annotations
-
- FW_Boolean CDrawPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_Boolean result = FW_CEmbeddingPart::InternalizeContent(ev, storageUnit, cloneInfo);
-
- // ----- Read general information -----
- if (result && storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream stream(sink);
- stream >> fCurrentPenSize;
- stream >> fRenderVerb;
- stream >> fAutoGrid;
- }
-
- return result;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ExternalizeContent
- //---------------------------------------------------------------------------------------
- // I override FW_CPart::ExternalizeContent because I want to write my annotations
-
- void CDrawPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- FW_CEmbeddingPart::ExternalizeContent(ev, storageUnit, cloneInfo);
-
- // ----- Write general information -----
- // FW_SUAddPropValue correctly test if the property and value exist before
- // trying to create them
- FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
-
- FW_PStorageUnitSink suSink(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CWritableStream stream(suSink);
- stream << fCurrentPenSize;
- stream << fRenderVerb;
- stream << fAutoGrid;
- }
-
- //---------------------------------------------------------------------------------------
- // CDrawPart::PrintInfoChanged
- //---------------------------------------------------------------------------------------
-
- void CDrawPart::PrintInfoChanged(Environment *ev, FW_CPrintInfo* printInfo)
- {
- if(printInfo != nil)
- {
- FW_CRect pageRect = printInfo->GetPageBounds();
- FW_CRect paperRect = printInfo->GetPaperBounds();
-
- FW_CPoint newSize(pageRect.Width(), pageRect.Height());
-
- long hRes, vRes;
-
- // print bounds are based on current printer resolution,
- // but our coordinate system is pixels
- if(printInfo->GetPrinterResolution(hRes, vRes))
- {
- newSize.x = newSize.x / (FW_IntToFixed(hRes) / FW_IntToFixed(72));
- newSize.y = newSize.y / (FW_IntToFixed(vRes) / FW_IntToFixed(72));
- }
-
- SetDrawingSize(ev, newSize);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewPartContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CDrawPart::NewPartContent(Environment* ev)
- {
- fPartContent = FW_NEW(CDrawPartContent, (ev, this));
- return fPartContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewLinkManager
- //----------------------------------------------------------------------------------------
- FW_CLinkManager* CDrawPart::NewLinkManager(Environment *ev)
- {
- CDrawLinkManager* linkMgr = FW_NEW(CDrawLinkManager, (ev, this));
- return linkMgr;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::AddShapeToPart
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::AddShapeToPart(Environment* ev, CBaseShape* shape)
- {
- fPartContent->AddShape(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::RemoveShapeFromPart
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::RemoveShapeFromPart(Environment* ev, CBaseShape* shape)
- {
- fPartContent->RemoveShape(ev, shape);
- shape->Removed(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAbout
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawPart::DoAbout(Environment* ev)
- {
- ::FW_About(ev, this, kAbout);
-
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_CString32 name("ODFDraw");
- FW_CString32 sorry("Sorry, not yet implemented!");
-
- FW_Handled result = FW_kHandled;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- if (cPen1 <= commandID && commandID <= cPen5)
- {
- int temp = cPen1;
- FW_Fixed penSize = FW_IntToFixed(commandID - temp + 1);
- if (!fDrawSelection->IsEmpty(ev))
- {
- CChangePenSizeCommand* cmd = FW_NEW(CChangePenSizeCommand, (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, penSize));
- cmd->Execute(ev);
- }
- else
- fCurrentPenSize = penSize;
- }
- else
- {
- switch (commandID)
- {
- case cHideShowPattern:
- fPatternWindow->ShowHide(ev, !fPatternWindow->IsShown(ev));
- break;
-
- case cHideShowPalette:
- fPaletteWindow->ShowHide(ev, !fPaletteWindow->IsShown(ev));
- break;
-
- case cHideShowTools:
- fToolsWindow->ShowHide(ev, !fToolsWindow->IsShown(ev));
- break;
-
- case cMoveForward:
- if (fPartContent->MoveForward(ev))
- {
- UpdateAfterMove(ev);
- this->Changed(ev);
- }
- break;
- case cMoveToFront:
- fPartContent->MoveToFront(ev);
- UpdateAfterMove(ev);
- this->Changed(ev);
- break;
- case cMoveBackward:
- if (fPartContent->MoveBackward(ev))
- {
- UpdateAfterMove(ev);
- this->Changed(ev);
- }
- break;
- case cMoveToBack:
- fPartContent->MoveToBack(ev);
- UpdateAfterMove(ev);
- this->Changed(ev);
- break;
-
- case cAutoGrid:
- fAutoGrid = !fAutoGrid;
- break;
-
- case cGroup:
- {
- CGroupShapesCommand* cmd = FW_NEW(CGroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
- cmd->Execute(ev);
- }
- break;
- case cUngroup:
- {
- CUngroupShapesCommand* cmd = FW_NEW(CUngroupShapesCommand, (ev, this->GetLastActiveFrame(ev), fDrawSelection));
- cmd->Execute(ev);
- }
- break;
-
- case cAlignObjects:
- case cAlignToGrid:
- case cRotate:
- case cFlipH:
- case cFlipV:
- case cLock:
- case cUnlock:
- case cScaleSelection:
- case cRoundCorners:
- FW_NoteAlert(name, sorry);
- break;
-
- case cInchUnit:
- case cCmUnit:
- case cPixelUnit:
- case cPicaUnit:
- fUnit = commandID;
- FW_NoteAlert(name, sorry);
- break;
-
- case cDegreesUnit:
- case cRadiansUnit:
- fArcUnit = commandID;
- FW_NoteAlert(name, sorry);
- break;
-
- default:
- result = FW_kNotHandled;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetTool
- //----------------------------------------------------------------------------------------
- void CDrawPart::SetTool(Environment* ev, unsigned short newTool)
- {
- if (fTool != newTool)
- {
- if (fTool == kSelectTool && !fDrawSelection->IsEmpty(ev))
- fDrawSelection->CloseSelection(ev);
-
- CheckTool(ev, fTool, newTool);
- fTool = newTool;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetRenderVerb(Environment* ev, unsigned short renderVerb)
- {
- if (fRenderVerb != renderVerb)
- {
- if (!fDrawSelection->IsEmpty(ev))
- {
- CChangeRenderVerbCommand* cmd = FW_NEW(CChangeRenderVerbCommand,
- (ev, this, this->GetLastActiveFrame(ev), fDrawSelection, renderVerb));
- cmd->Execute(ev);
- }
-
- unsigned short oldRenderVerb = fRenderVerb;
- fRenderVerb = renderVerb;
- CheckRenderVerb(ev, oldRenderVerb, fRenderVerb);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CDrawPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- FW_UNUSED(fromStorage);
- if (presentation == fPalettePresentation)
- {
- if (fPaletteFrame)
- return fPaletteFrame;
- else
- {
- fPaletteFrame = FW_NEW(CPaletteFrame, (ev, odFrame, presentation, this));
-
- CColorChangedInterest interest(fPaletteFrame);
- AddInterest(interest);
-
- return fPaletteFrame;
- }
- }
- else if (presentation == fPatternPresentation)
- {
- if (fPatternFrame)
- return fPatternFrame;
- else
- {
- fPatternFrame = FW_NEW(CPatternFrame, (ev, odFrame, presentation, this));
-
- CPatternChangedInterest interest(fPatternFrame);
- AddInterest(interest);
-
- return fPatternFrame;
- }
- }
- else if (presentation == fToolPresentation)
- {
- if (fToolFrame)
- return fToolFrame;
- else
- {
- fToolFrame = FW_NEW(CToolFrame, (ev, odFrame, presentation, this));
-
- CColorChangedInterest colorInterest(this);
- fToolFrame->AddInterest(colorInterest);
- CPatternChangedInterest patternInterest(this);
- fToolFrame->AddInterest(patternInterest);
-
- return fToolFrame;
- }
- }
-
- return FW_NEW(CDrawFrame, (ev, odFrame, presentation, this));
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_UNUSED(isRoot);
- if (!hasMenuFocus)
- return FW_kNotHandled;
-
- ODCommandID command;
- FW_Boolean hasSelection = fDrawSelection->Count() > 0;
-
- // ----- Edit Menu -----
- menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountShapes() > 0);
-
- // ----- PenSize Menu -----
- FW_Fixed penSize = fCurrentPenSize;
- if (fDrawSelection->Count() >= 1)
- {
- if (!fDrawSelection->GetSelectionPenSize(ev, penSize))
- {
- penSize = FW_kFixed0;
- }
- }
- command = FW_FixedToInt(penSize) + cPen1 - 1;
-
- for (ODCommandID p = cPen1; p <= cPen5; p++)
- menuBar->EnableAndCheckCommand(ev, p, TRUE, p == command);
-
- FW_Boolean readWrite = !IsReadOnly(ev);
-
- // ----- Arrange Menu -----
- menuBar->EnableCommand(ev, cMoveForward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToFront, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveBackward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToBack, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignToGrid, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignObjects, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRotate, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipH, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipV, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cGroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUngroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cLock, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUnlock, readWrite && hasSelection);
-
- // ----- Options Menu -----
- menuBar->EnableAndToggleCommand(ev, cAutoGrid, TRUE, !fAutoGrid);
- menuBar->EnableCommand(ev, cScaleSelection, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRoundCorners, TRUE);
-
- // ----- Units Menu -----
- menuBar->EnableAndCheckCommand(ev, cInchUnit, TRUE, fUnit == cInchUnit);
- menuBar->EnableAndCheckCommand(ev, cCmUnit, TRUE, fUnit == cCmUnit);
- menuBar->EnableAndCheckCommand(ev, cPixelUnit, TRUE, fUnit == cPixelUnit);
- menuBar->EnableAndCheckCommand(ev, cPicaUnit, TRUE, fUnit == cPicaUnit);
- menuBar->EnableAndCheckCommand(ev, cDegreesUnit, TRUE, fArcUnit == cDegreesUnit);
- menuBar->EnableAndCheckCommand(ev, cRadiansUnit, TRUE, fArcUnit == cRadiansUnit);
-
- // ----- Window Menu -----
- menuBar->EnableAndToggleCommand(ev, cHideShowTools, TRUE, fToolsWindow == NULL || !fToolsWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPalette, TRUE, fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPattern, TRUE, fPatternWindow == NULL || !fPatternWindow->IsShown(ev));
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckTool
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckTool(Environment* ev, unsigned short oldTool, unsigned short newTool)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckTool(ev, oldTool, newTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckRenderVerb(Environment* ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckRenderVerb(ev, oldRenderVerb, newRenderVerb);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::UpdateAfterMove
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::UpdateAfterMove(Environment* ev)
- {
- CDrawFacetClipper facetClipper(this);
- facetClipper.Clip(ev, fMainPresentation, fDrawSelection->GetUpdateShape());
-
- fMainPresentation->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NotifyForColorChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::NotifyForColorChanged(Environment *ev, const FW_CColor& color, FW_ERenderVerbs renderVerb)
- {
- CColorChangedInterest interest(this);
- CColorChangedNotification notification(interest, color, renderVerb);
- Notify(ev, notification);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NotifyForPatternChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::NotifyForPatternChanged(Environment *ev, short patIndex, FW_ERenderVerbs renderVerb)
- {
- CPatternChangedInterest interest(this);
- CPatternChangedNotification notification(interest, patIndex, renderVerb);
- Notify(ev, notification);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetColor
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetColor(Environment *ev, const FW_CColor& color, FW_ERenderVerbs renderVerb)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- if (renderVerb == FW_kFrame)
- fFrameColor = color;
- else
- fFillColor = color;
- NotifyForColorChanged(ev, color, renderVerb);
- }
- else
- {
- CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
- (ev, (renderVerb == FW_kFrame ? cChangeFrameColor: cChangeFillColor), this, this->GetLastActiveFrame(ev), fDrawSelection, color));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetPattern
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetPattern(Environment *ev, short newFillPatIndex, FW_ERenderVerbs renderVerb)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- if (renderVerb == FW_kFrame)
- fFramePatIndex = newFillPatIndex;
- else
- fFillPatIndex = newFillPatIndex;
- NotifyForPatternChanged(ev, newFillPatIndex, renderVerb);
- }
- else
- {
- FW_CPattern pattern = GetPattern(newFillPatIndex).Copy();
- CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
- (ev, (renderVerb == FW_kFrame ? cChangeFramePattern : cChangeFillPattern), this, this->GetLastActiveFrame(ev), fDrawSelection, pattern));
- cmd->Execute(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::WhichShape
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawPart::WhichShape(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent, FW_Boolean hasToBeSelected) const
- {
- CDrawContentShapeIterator ite(fPartContent);
- for (CBaseShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
- {
- FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && shape->IsSelectedShape());
- if (test && shape->HitTest(ev, gc, theMouseEvent))
- return shape;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::FindShapeWithIndex
- //----------------------------------------------------------------------------------------
- CBaseShape* CDrawPart::FindShapeWithIndex(short extIndex)
- {
- // Search the shape list and return the shape with the specified externalization index
- CDrawContentShapeIterator ite(fPartContent);
- for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->GetExternalizationIndex() == extIndex)
- return shape;
- }
-
- // extIndex not found!?
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoPostCreate
- //----------------------------------------------------------------------------------------
- void CDrawPart::DoPostCreate(Environment* ev)
- {
- // Perform "DoPostCreate"-type initialization.
- // In our case, we want to make sure that any subscribers that were just internalized
- // get registered for automatic updates.
-
- if (!fPostCreated) // do this only once!
- {
- CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
- linkMgr->RegisterLinks(ev);
- fPostCreated = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewElementIterator
- //----------------------------------------------------------------------------------------
-
- FW_CElementIterator* CDrawPart::NewElementIterator(Environment* ev,
- FW_CPart* part,
- ODDescType desiredClass) const
- {
- FW_CElementIterator* iter;
-
- unsigned short shapeType;
-
- if (desiredClass == typeWildCard || desiredClass == kShapeClass || ShapeClassToType(desiredClass, shapeType))
- iter = FW_NEW(CSemanticShapeElementIterator, (fPartContent, desiredClass));
- else
- iter = FW_MEmbeddingPartScriptable::NewElementIterator(ev, part, desiredClass);
-
- return iter;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAECreateElement
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::DoAECreateElement(Environment* ev,
- FW_CPart* part,
- const FW_CAppleEvent& event,
- FW_CAppleEvent& reply)
- {
- ODDescType shapeClass = event.GetType(keyAEObjectClass);
- unsigned short shapeType;
-
- if (ShapeClassToType(shapeClass, shapeType))
- {
- CBaseShape* theShape = GetDrawContent()->NewShape(ev, shapeType);
- FW_CColor color;
-
- theShape->SetFrameInk(FW_kNormalInk);
- theShape->SetFrameStyle(FW_kNormalStyle);
-
- theShape->ChangeRenderVerb(ev, GetRenderVerb());
- theShape->ChangePenSize(ev, GetPenSize());
-
- GetFrameColor(color);
- theShape->ChangeFrameColor(ev, color);
-
- GetFillColor(color);
- theShape->ChangeFillColor(ev, color);
-
- theShape->ChangeFramePattern(ev, GetFramePattern());
- theShape->ChangeFillPattern(ev, GetFillPattern());
-
- FW_CPoint topLeft(FW_IntToFixed(10), FW_IntToFixed(10));
- FW_CPoint botRight(FW_IntToFixed(82), FW_IntToFixed(82));
-
- theShape->SetShapeGeometry(topLeft, botRight);
-
- if (event.HasDataKey(keyAEPropData))
- {
- FW_CDesc properties;
- event.GetDataByDesc(properties, keyAEPropData, typeAERecord);
- theShape->SetProperties(ev, part, properties);
- }
-
- CDrawShapeCommand* cmd = FW_NEW(CDrawShapeCommand,
- (ev, this, FW_MScriptable::GetFrame(ev, part), fDrawSelection, theShape));
-
- cmd->Execute(ev);
-
- GetDrawContent()->RedrawShape(ev, theShape);
-
- FW_CDesc objectSpec;
-
- BuildObjectSpecifier(ev, part, FW_MScriptable::GetFrame(ev, part), objectSpec, GetSpecifierForm());
- reply.PutDataByDesc(objectSpec, keyAEResult);
- }
- else
- FW_MEmbeddingPartScriptable::DoAECreateElement(ev, part, event, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ShapeClassToType
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawPart::ShapeClassToType(ODDescType shapeClass,
- unsigned short& shapeType) const
- {
- FW_Boolean result = TRUE;
-
- switch(shapeClass)
- {
- case cLine:
- shapeType = kLineShape;
- break;
-
- case cRectangle:
- shapeType = kRectShape;
- break;
-
- case cOval:
- shapeType = kOvalShape;
- break;
-
- case cRoundedRectangle:
- shapeType = kRRectShape;
- break;
-
- case cText:
- shapeType = kTextShape;
- break;
-
- default:
- result = FALSE;
- break;
- }
-
- return result;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::EmbeddedFrameRemoved
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
- {
- CProxyShape* proxyShape = (CProxyShape*)proxy;
-
- FW_CRect updateBox;
- proxyShape->GetUpdateBox(updateBox);
-
- fMainPresentation->Invalidate(ev, updateBox);
-
- // ----- I don't need to call RemoveShapeFromPart because the embedded frames have already been
- // ----- deleted (ODF calls FW_MProxy::RemoveEmbeddedFrames)
- fPartContent->RemoveShape(ev, proxyShape);
- delete proxyShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- switch (notification.GetMessage()) {
- case kColorChanged:
- {
- CColorChangedNotification& colorNotification = (CColorChangedNotification&)notification;
- SetColor(ev, colorNotification.GetColor(), colorNotification.GetRenderVerb());
- }
- break;
- case kPatternChanged:
- {
- CPatternChangedNotification& patternNotification = (CPatternChangedNotification&)notification;
- SetPattern(ev, patternNotification.GetPattern(), patternNotification.GetRenderVerb());
- }
- break;
- };
- }
-
-